package com.itheima.exer.homework.hw1011.system;

public class Cooker implements Runnable {
    private static Desk desk;

    public Cooker(Desk desk) {
        Cooker.desk = desk;
    }

    @Override
    public void run() {

            while (true) {
                synchronized (desk.getObject()) {
                    if (desk.getCount() == 0){
                        break;
                    }else {
                        if (!desk.isFlag()) {
                            System.out.println("厨师在制作汉堡包!");
                            desk.setFlag(true);
                            desk.getObject().notifyAll();
                            /*try {
                                desk.getObject().wait();
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }*/
                        }else {
                            try {
                                desk.getObject().wait();
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }
            }

    }
}
